import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Observable } from 'rxjs';
import { Socket } from 'socket.io';
import { Reflector } from '@nestjs/core';

@Injectable()
export class RoomWSInitGuard implements CanActivate {
    canActivate(context: ExecutionContext): boolean {
        const client: Socket = context.switchToWs().getClient<Socket>();
        const hasRoom = this.validateRequest(client);

        return hasRoom;
    }

    private validateRequest(client: Socket): boolean {
        return Boolean(client.data?.roomId);
    }
}
